package com.myoffice.biz.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.myoffice.biz.RepairBiz;
import com.myoffice.biz.UserInfoBiz;
import com.myoffice.dao.BaseDaoI;
import com.myoffice.model.TSysfun;
import com.myoffice.model.TUserinfo;

@Service("repairBiz")
public class RepairBizImpl implements RepairBiz {
	
	private BaseDaoI<TSysfun> tSysfunDao=null;
	private BaseDaoI<TUserinfo> tUserinfo=null;
	
	
	
	public BaseDaoI<TUserinfo> gettUserinfo() {
		return tUserinfo;
	}
	@Autowired
	public void settUserinfo(BaseDaoI<TUserinfo> tUserinfo) {
		this.tUserinfo = tUserinfo;
	}
	public BaseDaoI<TSysfun> gettSysfunDao() {
		return tSysfunDao;
	}
	@Autowired
	public void settSysfunDao(BaseDaoI<TSysfun> tSysfunDao) {
		this.tSysfunDao = tSysfunDao;
	}

	synchronized public void deleteAndRepair() {
//		bugDao.executeHql("delete Tbug");
//		onlineDao.executeHql("delete Tonline");
//		tSysfunDao.executeHql("update TSysfun t set t.displayname = null");
		tSysfunDao.executeHql("delete TSysfun");
//		roleauthDao.executeHql("delete Troletauth");
//		userroleDao.executeHql("delete Tusertrole");
//		authDao.executeHql("update Tauth t set t.tauth = null");
//		authDao.executeHql("delete Tauth");
//		roleDao.executeHql("delete Trole");
//		userDao.executeHql("delete Tuser");
//		repair();
	}

	synchronized public void repair() {
		repairTSysfun();// 修复菜单
//		repairAuth();// 修复权限
//		repairRole();// 修复角色
		repairUser();// 修复用户
//		repairRoleAuth();// 修复角色和权限的关系
//		repairUserRole();// 修复用户和角色的关系
	}

	private void repairUser() {
		TUserinfo tu=new TUserinfo();
		tu.setId("1");
		tu.setName("admin");
		tu.setPassword("admin");
		tu.setGender("男");
		this.tUserinfo.saveOrUpdate(tu);
	}
	private void repairTSysfun(){
		TSysfun sy=new TSysfun();
		sy.setId("sy");
		sy.setText("首页");
		sy.setDisplayoder(1);
		sy.setNodeurl("");
		this.tSysfunDao.saveOrUpdate(sy);
		
		TSysfun xtglRoot= new TSysfun();
		xtglRoot.setId("xtglRoot");
		xtglRoot.setText("系统管理");
		xtglRoot.setTSysfun(sy);
		xtglRoot.setDisplayoder(1);
		xtglRoot.setNodeurl("/admin/xtgl.jsp");
		this.tSysfunDao.saveOrUpdate(xtglRoot);
		
		TSysfun yhgl= new TSysfun();
		yhgl.setId("yhgl");
		yhgl.setText("用户管理");
		yhgl.setDisplayoder(2);
		yhgl.setTSysfun(xtglRoot);
		yhgl.setNodeurl("/admin/yhgl.jsp");
		this.tSysfunDao.saveOrUpdate(yhgl);
		
		TSysfun jsgl= new TSysfun();
		jsgl.setId("jsgl");
		jsgl.setText("角色管理");
		jsgl.setDisplayoder(3);
		jsgl.setTSysfun(xtglRoot);
		jsgl.setNodeurl("");
		this.tSysfunDao.saveOrUpdate(jsgl);
		
		TSysfun dlrj= new TSysfun();
		dlrj.setId("dlrj");
		dlrj.setText("登录日记");
		dlrj.setDisplayoder(4);
		dlrj.setTSysfun(xtglRoot);
		dlrj.setNodeurl("");
		this.tSysfunDao.saveOrUpdate(dlrj);
		
		TSysfun czrj= new TSysfun();
		czrj.setId("czrj");
		czrj.setText("操作日记");
		czrj.setDisplayoder(5);
		czrj.setTSysfun(xtglRoot);
		czrj.setNodeurl("");
		this.tSysfunDao.saveOrUpdate(czrj);
		
		TSysfun cdcx= new TSysfun();
		cdcx.setId("cdcx");
		cdcx.setText("菜单管理");
		cdcx.setDisplayoder(6);
		cdcx.setTSysfun(xtglRoot);
		cdcx.setNodeurl("/admin/cdgl.jsp");
		this.tSysfunDao.saveOrUpdate(cdcx);		
	}
}
